package ebj.common.document_create.pdf;
import java.io.FileOutputStream;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfWriter;

import ebj.common.document_create.helper.CustomHeaderFooter;
import ebj.common.document_create.helper.ITextHelper;

public class HeaderAndFooterDemo {
    public static void main(String[] args){
        String file_path = ITextHelper.getAbsoluteOutputFilePath(HeaderAndFooterDemo.class.getSimpleName());
        
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try{
            PdfWriter writer=PdfWriter.getInstance(document,
                    new FileOutputStream(file_path) );
            Rectangle rect = new Rectangle(36, 54, 559, 788);
            rect.setBorderColor(BaseColor.BLACK);
            writer.setBoxSize("art", rect);
//            HeaderFooter header=new HeaderFooter();
//            TableHeader header = new TableHeader();
            CustomHeaderFooter headerFooter = new CustomHeaderFooter();
            headerFooter.setCourseName("西方经济学");
            headerFooter.setTitle("2016年10月 题库考试 模拟题");
            writer.setPageEvent(headerFooter);
            
            document.open();

            document.newPage();
            Paragraph par = new Paragraph("first paragraph");
            document.add(par);

            document.newPage();
            Paragraph par2 = new Paragraph("second paragraph");
            document.add(par2);

            document.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}